<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>订阅数据变化</title>
</head>

<body>
    <h1>订阅数据变化</h1>
    <div style="color:gray">
        <p>使用`vm.$watch`订阅数据变化。</p>
    </div>
    <div>
        <a href="/">回目录</a>
    </div>
    <hr>
    <div id="app">
        {{ a }}
    </div>
    <script src="/node_modules/vue/dist/vue.js"></script>
    <script>
        var data = {
            a: 1
        };

        var app = new Vue({
            el: "#app",
            data: data
        });

        app.$watch("a", function (newValue, oldValue) {
            console.log("a = " + app.a);
            console.log("newValue = " + newValue);
            console.log("oldValue = " + oldValue);
        });
    </script>
</body>

</html>